//
//  PYCornerButtonCell.m
//  IHome
//
//   Created by zhujizheng on 2020/2/18.
//  Copyright © 2019年 com.zhujizheng. All rights reserved.
//

#import "PYCornerButtonCell.h"

@interface PYCornerButtonCell ()

@property (nonatomic, strong) UIButton *btn;
@property (nonatomic, weak) id<PYCornerButtonCellDelegate> delegate;
@end

@implementation PYCornerButtonCell

+ (instancetype)cellWithTableView:(UITableView *)tableView delegate:(nullable id<PYCornerButtonCellDelegate>)delegate
{
    PYCornerButtonCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cornerbuttoncellid"];
    if (!cell) {
        cell = [[PYCornerButtonCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cornerbuttoncellid"];
        [cell initBtn];
    }
    cell.delegate = delegate;
    return cell;
}

- (void)enableBtn
{
    self.btn.enabled = YES;
    self.btn.alpha = 1;
}

- (void)disableBtn
{
    self.btn.enabled = NO;
    self.btn.alpha = 0.5;
}
#pragma mark - btn
- (UIButton *)btn
{
    if (!_btn) {
        _btn = [UIButton new];
        _btn.layer.cornerRadius = 4;
        _btn.layer.masksToBounds = YES;
        _btn.backgroundColor = PY_APP_Main_Color;
        _btn.titleLabel.font = PY_Font_Default;
    }
    return _btn;
}

- (void)initBtn
{
    [self.contentView addSubview:self.btn];
    [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(13);
        make.right.mas_equalTo(-13);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(45);
    }];
    [self.btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
}

- (void)btnAction
{
    if ([self.delegate respondsToSelector:@selector(clickButton:)]) {
        [self.delegate clickButton:self];
    }
}

@end
